{* $Id$ *}
{include_core file="admin/lib/header.html" title="菜单展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">菜单管理<span>在这里对菜单进行管理</span></h2>
    <a href="{AnUrl('admin_menu/admin/add')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>添加菜单</a>
  </div>
  <!--start:列表-->
  <table class="list-table">
    <caption>按状态：
      <a href='{AnUrl("admin_menu/admin?status=1")}' {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>正常</a>
      <a href='{AnUrl("admin_menu/admin?status=0")}' {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已删除</a>
    </caption>
    <thead><tr>
      {if $status == 1}
      <th style="width:20px;"><input type="checkbox" class="selectAll"></th>
      {/if}
      <th>菜单标题</th>
      <th>父级菜单</th>
      <th style="min-width:100px">菜单标识</th>
      <!-- <th style="min-width:130px;">排序</th> -->
      <th style="width:130px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $admin_menu_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          {if $status == 1}
          <td><input type="checkbox" class="listSelect"></td>
          {/if}
          <td>{$v.title}</td>
          <td>{admin_menu_helper::get_menu_title($v.parent_id)}</td>
          <td>{$v.module}{if $v.module}/admin{/if}{if $v.controller}/{/if}{$v.controller}</td>
          <td>
            {if $status == 1}
              <a href="{AnUrl("admin_menu/admin/edit?id={$v.id}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              <a href="{AnUrl("admin_menu/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs deleteOne"><i class="icon-trash icon-white"></i>删除</a>
            {elseif $status == 0}
              <a href="{AnUrl("admin_menu/admin/change_status?status=1")}" class="btn btn-success btn-xs changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
            {/if}
          </td>
        </tr>
        {if $v.children}
          {foreach $v.children as $key=>$value}
          <tr id="dataList{$value.id}" {if $key%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
            {if $status == 1}
            <td><input type="checkbox" class="listSelect"></td>
            {/if}
            <td><div style="position:relative;"><img src="{$smarty.const.SITE_URL}/images/category_prefix.png" style="position:absolute;top:-4px;" width="12"></div><span style="margin-left:20px;">{$value.title}</span></td>
            <td>{admin_menu_helper::get_menu_title($value.parent_id)}</td>
            <td>{$value.module}{if $value.module}/admin{/if}{if $value.controller}/{/if}{$value.controller}</td>
            <td>
              {if $status == 1}
                <a href="{AnUrl("admin_menu/admin/edit?id={$value.id}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
                <a href="{AnUrl("admin_menu/admin/delete?id={$value.id}")}" class="btn btn-danger btn-xs deleteOne"><i class="icon-trash icon-white"></i>删除</a>
              {elseif $status == 0}
                <a href="{AnUrl("admin_menu/admin/change_status?status=1")}" class="btn btn-success btn-xs changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
              {/if}
            </td>
          </tr>
          {/foreach}
        {/if}
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" class="selectAll"></td><td colspan="5"><a href="{AnUrl("admin_menu/admin/delete")}" class="btn btn-danger btn-xs deleteAll">批量删除</a></td></tr></tfoot>
    {/if}
  </table>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
<script>
var resName = 'admin_menu';
var jsCategoryId = "{$search_filter.category_id}";
$('.js_categoryId').load(siteUrl+'/category/load_category_option?res_name='+resName,function(){
  $('.js_categoryId').find('option').each(function(){
    if ($(this).attr('value') == jsCategoryId) {
      $(this).attr('selected','selected');
    }
  });
});
$(function(){
  // 高级搜索
  $('.js_advanced').click(function(e){
    e.preventDefault();
    var thisObj = $(this);
    var outBox  = thisObj.closest('form');
    if (thisObj.hasClass('js_isOpen')) {
      thisObj.removeClass('js_isOpen open');
      outBox.find('input').show();
      outBox.find('button').show();
      $('.js_advancedForm').hide();
    } else {
      thisObj.addClass('js_isOpen open');
      outBox.find('input').hide();
      outBox.find('button').hide();
      $('.js_advancedForm').show();
    }
  });
  
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });

  // 页面复制
  var clip = new ZeroClipboard( $('.js_copyList'), {
    moviePath: "../../../../js/zclip/ZeroClipboard.swf"
  });
  clip.on( 'complete', function(client, args) {
    showMsg("复制成功，复制内容为："+ args.text, 1);
  });
  
  // 查看预览效果
  $('.js_previewBtn').each(function(i){
    $(this).click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var resName = 'admin_menu';
      var resId = thisObj.closest('tr').attr('data-id');
      
      showPreviewDialog(resName, resId);
    });
  });
});
</script>
{include_core file="admin/lib/footer.html"}